// ======================================================================
// Copyright (C) 2013 Hell-Prototypes. / www.hellprototypes.com
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// ======================================================================
#include "controler_status.h"

controler_status::controler_status(QWidget *parent) :
    QWidget(parent)
{
    m_layout = new QHBoxLayout(this);
    m_layout->setSpacing(3);
    m_layout->setContentsMargins(0,1,0,1);

    QStringList tips;
    tips << "Enable" << "DIR 0" << "DIR 1" << "Pump" << "X Left" << "X Right" << "Y Front" << "Y Back";

    for(int i=0; i<8; i++) {
        m_status_show[i] = new QLabel(this);
        m_status_show[i]->setMaximumSize(12,24);
        m_status_show[i]->setStyleSheet("background-color:Red");
        m_status_show[i]->setToolTip(tips.at(i));
        m_layout->addWidget(m_status_show[i]);
    }
    this->setLayout(m_layout);
    this->setToolTip("0: Red, 1: Green");
}

void controler_status::slot_controller_status_update(int status)
{
    int mark = 1;
    for(int i=0; i<8; i++) {
        if(status & mark) {
            m_status_show[i]->setStyleSheet("background-color:Green");
        } else {
            m_status_show[i]->setStyleSheet("background-color:Red");
        }
        mark <<= 1;
    }
}
